// yb_shop/pages/miaosha/seckillList/index.js
var t = getApp(),
  a = t.requirejs("core");
Page({
  data: {
    currentTab: 1,
    page: 0,
    pageList: [],
    countDownList: [],
    countDownList2:[],
    loading: true
  },
  onLoad: function (options) {
    this.setCurrentData()
  },
  onShow: function () {
  },
  setCurrentData: function () {
    var t = this;
    var currentTab=t.data.currentTab;
    t.setData({
      loading: true
    }),
      a.get("Miaosha/msGoodsList", {
        page: t.data.page,
        ms_type: t.data.currentTab,
       // uid: getApp().getCache("userinfo").uid
      }, function (e) {
       if(e.code==0){
         if(e.info.length>0){
           e.info.forEach(function(v,k){
             var time = v.etime;
             a.Countdown(time, function (i) {
             
               if (currentTab==1){
                 var countDownList = t.data.countDownList;
                 if (i.show_time != false) {
                   i.show_time = true;
                 }
                 countDownList[k] = i;
                 t.setData({ countDownList: countDownList });
               }else{
                 var countDownList2 = t.data.countDownList2;
                 if (i.show_time != false) {
                   i.show_time = true;
                 }
                 countDownList2[k] = i;
                 t.setData({ countDownList2: countDownList2 });
               }
               
             })
           })
         }
         console.log(e)
          t.setData({
            loading: false,
            show: true
          });
            e.info.length > 0 && t.setData({
              page: t.data.page + 1,
              pageList: t.data.pageList.concat(e.info)
            });
            e.info.length < 10 && t.setData({
              loaded: true
            })
       }else{
         a.alert(e.msg)
       }
      }, true)
  },
 
  // 点击tab切换 
  changeList: function (e) {
    if (this.data.currentTab == e.currentTarget.dataset.list) return;
    this.setData({
      currentTab: e.currentTarget.dataset.list
    })
    this.setData({
      pageList: [],
      page: 1,
      loaded: false,
    })
    this.setCurrentData();
  },
  /**
   * 下拉刷新
   */
  onPullDownRefresh: function () {
    this.setData({
      pageList: [],
      page: 1,
      loaded: false,
    })
    this.setCurrentData()
    wx.stopPullDownRefresh();
  },
  /**
  *上拉加载
  */
  onReachBottom: function () {
    console.log('加载更多')
    this.data.loaded || this.setCurrentData()
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})